package com.yogee.topseller.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.CorrectionInfo;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yogee.topseller.R;
import com.yogee.topseller.activity.ProductDetailsActivity;
import com.yogee.topseller.bean.CenterInfoBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @auathor ${XiaoJianghong}
 * @date 2017/7/22.
 */

public class ButlerServiceMessageRvAdapter extends RecyclerView.Adapter<ButlerServiceMessageRvAdapter.ItemHolder> {

    private Context context;
    private List<CenterInfoBean.Centers> data;

    public ButlerServiceMessageRvAdapter(Context context) {
        this.context = context;
    }

    public void addData(List<CenterInfoBean.Centers> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_butler_message, parent, false);
        return new ItemHolder(view);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, int position) {
        final CenterInfoBean.Centers bean = data.get(position);
        holder.messageTv.setText(bean.getCenter());
        holder.timeTv.setText(bean.getTime());
        holder.rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, ProductDetailsActivity.class).putExtra("id",bean.getProId()).putExtra("isFast","0"));
            }
        });
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    class ItemHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_butler_message_tv)
        TextView messageTv;
        @BindView(R.id.item_butler_message_time_tv)
        TextView timeTv;
        @BindView(R.id.item_butler_message_rl)
        RelativeLayout rl;

        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
